Technical Q&A QA1059
Setting the look-and-feel for Swing applications


Q: I don't want my Swing applications to use Aqua on OS X. Can I change this?

A:  As specified by Sun, Swing applications can use multiple pluggable look-and-feel (PLAF)s that can be changed dynamically, depending on how an application is written. By default, Swing applications on Mac OS X will adopt the Aqua look-and-feel. This is done through use of a swing.properties file that is used by the Java Virtual Machine when launching a Swing app. This can be overridden a few different ways:

  • For programs launched from Terminal, add a -Dswing.defaultlaf=<fullClassName> argument to the java executable. This will override the default value in swing.properties.

  • In a bundled ".app" application, the above property can be set in the Info.plist file.

To override the default PLAF permanently on your Mac OS X system, you'll need to modify swing.properties from the command line:

  1. cd /Library/Java/Home/lib
  2. Open swing.properties with a text editor as the root user (either logged in as root, or using sudo
  3. Prepend the existing swing.defaultlaf line with a # to comment out the original entry.
  4. Add a new line that reads swing.defaultlaf=<fullClassName>
  5. Save and close the file.

It is not recommended that you, as a developer, perform this step on user machines where more applications than yours may be running. The other techniques listed above are more suitable for a deployment situation, as they only affect your application.

The exception to this is Java Web Start applications, which start up after Java Web Start has initialized the AWT with Aqua as the default PLAF. If you want your Java Web Start app to use a different PLAF, you will need to do so by calling UIManager.setLookAndFeel.

Please Note that setting the PLAF programmatically will override all of the other techniques listed above. If the program you are using has programmatically set Aqua or Metal, for instance, it won't matter what swing.properties, -D, or your Info.plist request. For this reason, it is best to stay away from hard-coding the PLAF, as it would require a code change to switch the PLAF, as opposed to a property change.

For more information on changing the look-and-feel of a Swing application, please see The Java Tutorial.


[Feb 10, 2004]


Developer Documentation | Technical Notes | Development Kits | Sample Code